#ifndef __GAME_TIMER_H__
#define __GAME_TIMER_H__

#include "game_def.h"
#include "game_event.h"

class CGameTimerEvent:public CGameEvent{
public:
  CGameTimerEvent(const char* type,CGameRef* currentTarget):CGameEvent(type,currentTarget){
  };
  static const char* TIMER;
  static const char* TIMER_COMPLETE;
};




class CGameTimer:public CGameEventDispatcher{
protected:
  UINT32 _delay;
  UINT32 _repeat;
  BOOL _running;
  UINT32 _currentCount;
  event* _event;
  void tick();
  void onTick();
  template <typename TYPE, void (TYPE::*onTick)() >  
  static void __timer_cb(int sock, short which, void *arg) ;
public:
  CGameTimer();
  virtual ~CGameTimer();
  BOOL init(event_base* evbase,mseconds_t delay, UINT32 repeat);
  BOOL init(mseconds_t delay, UINT32 repeat);
  BOOL init();
  void reset();
  void stop();
};

#endif
